﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;


namespace PersianCalendarControl
{
	public partial class HeaderLabel : UserControl
	{
        public delegate void HeaderLabelClickedEvent(object sender, RoutedEventArgs e);

        public event HeaderLabelClickedEvent OnHeaderLabelClicked;

        private PersianCalendar _calendar;
        private CalendarViewState currentView = CalendarViewState.MonthView;
        public CalendarViewState CurrentView
        {
            get { return currentView; }
            set { currentView = value; }
        }
		public HeaderLabel()
		{
			// Required to initialize variables
			InitializeComponent();
		    _calendar = new PersianCalendar(); 
		}

        private DateTime _currentDate = DateTime.Now;
        public DateTime CurrentDate
        {
            get { return _currentDate; }
            set
            {
                _currentDate = value;
                Refresh();
            }
        }

        private void Refresh()
        {
            switch(currentView)
            {
                case CalendarViewState.MonthView:
                    int m = _calendar.GetMonth(_currentDate);
                    headerButton.Content = _calendar.MonthNames[_calendar.GetMonth(_currentDate)] + " " + _calendar.GetYear(_currentDate);
                    break;
                case CalendarViewState.YearView:
                    headerButton.Content = _calendar.GetYear(_currentDate);
                    break;
                case CalendarViewState.DecadeView:
                    headerButton.Content = ( _calendar.GetYear(_currentDate) - 6) + "-" +( _calendar.GetYear(_currentDate) + 5);
                    break;

            }
           
        }

        private void headerButton_Click(object sender, RoutedEventArgs e)
        {
            OnHeaderLabelClicked(this,e);
        }
	}
}